<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/10/13
  Time: 10:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Employees</title>
    <%--
        SpringMVC处理静态资源
        1.为什么会有这样的问题：
        优雅的REST风格的资源URL不希望带.html或.do等后缀。若将DispatcherServlet请求映射配置为/，则SpringMVC将捕获WEB容器的所有请求，包括静态资源的处理请求，SpringMVC会将它们当成一个普通的请求进行处理，因此找不到对应的处理器将导致错误。
        2.解决：
        可以在SpringMVC的配置文件中配置<mvc:default-servlet-handler/>的方式解决静态资源的问题。
    --%>
    <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                var href = $(this).attr("href");
                $("form").attr("action", href).submit();
                return false;
            })
        })
    </script>
</head>
<body>
<h4>Employees info</h4>
<form action="" method="post">
    <input type="hidden" name="_method" value="DELETE">
</form>

<c:if test="${empty requestScope.employees}">
    没有任何员工信息
</c:if>
<c:if test="${!empty requestScope.employees}">
    <table border="1" cellspacing="1" cellpadding="10">
        <tr>
            <th>id</th>
            <th>lastName</th>
            <th>gender</th>
            <th>email</th>
            <th>department</th>
            <th>edit</th>
            <th>delete</th>
        </tr>
        <c:forEach items="${requestScope.employees}" var="employee">
            <tr>
                <td>${employee.id}</td>
                <td>${employee.lastName}</td>
                <td>${employee.gender==0?'female':'male'}</td>
                <td>${employee.email}</td>
                <td>${employee.department.departmentName}</td>
                <td><a href="${pageContext.request.contextPath}/emp/${employee.id}">EDIT</a></td>
                <td><a class="delete" href="${pageContext.request.contextPath}/emp/${employee.id}">DELETE</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
<br><br>
<a href="emp">Add new employee</a>
</body>
</html>
